    //
    //  XOShoppingCartListModel.m
    //  EnjoyShoppingStreet
    //
    //  Created by lifayu on 2018/3/16.
    //  Copyright © 2018年 lifayu. All rights reserved.
    //

#import "XOShoppingCartListModel.h"

@implementation XOShoppingCartListModel

- (NSString *)getArrayObjectClassNameForArrayName:(NSString *)arrayName{
    return @"XOShoppingCartModel";
}


- (BOOL)wholeSelected{
    if(!self.list || self.list.count == 0){
        return NO;
    }
    for (XOShoppingCartModel *model in self.list) {
        if(!model.wholeSelected){
            return NO;
        }
    }
    return YES;
}

- (void)setWholeSelected:(BOOL)wholeSelected{
    for (XOShoppingCartModel *model in self.list) {
        model.wholeSelected = wholeSelected;
    }
}

- (NSArray *)selectedGoodsList{
    NSMutableArray *selectGoods = [NSMutableArray array];
    for (XOShoppingCartModel *model in self.list) {
        for (EJSShoppingCartGoodsModel *goodsModel in model.carts) {
            if(goodsModel.selectState){
                [selectGoods addObject:goodsModel];
            }
        }
    }
    return selectGoods;
}

- (NSArray *)wholeGoodsList{
    NSMutableArray *wholeGoods = [NSMutableArray array];
    for (XOShoppingCartModel *model in self.list) {
        for (EJSShoppingCartGoodsModel *goodsModel in model.carts) {
            [wholeGoods addObject:goodsModel];
        }
    }
    return wholeGoods;
}

- (CGFloat)selectedGoodsTotalPrice{
    CGFloat price = 0.0;
    for (XOShoppingCartModel *model in self.list) {
        for (EJSShoppingCartGoodsModel *goodsModel in model.carts) {
            if(goodsModel.selectState){
                price += goodsModel.num.integerValue*goodsModel.price.floatValue;
            }
        }
    }
    return price;
}

- (BOOL)hasSelectedGoods{
    for (XOShoppingCartModel *model in self.list) {
        for (EJSShoppingCartGoodsModel *goodsModel in model.carts) {
            if(goodsModel.selectState){
                return YES;
            }
        }
    }
    return NO;
}

- (void)deleteGoods:(EJSShoppingCartGoodsModel *)goodsModel{
    for (XOShoppingCartModel *model in self.list) {
        for (EJSShoppingCartGoodsModel *goodsModel1 in model.carts) {
            if([goodsModel.cartId isEqualToString:goodsModel1.cartId]){
                NSMutableArray *goodsList = [model.carts mutableCopy];
                [goodsList removeObject:goodsModel1];
                model.carts = goodsList;
                return;
            }
        }
    }
}

- (void)deleteAllGoods{
    for (XOShoppingCartModel *model in self.list) {
        model.carts = nil;
//        for (EJSShoppingCartGoodsModel *goodsModel1 in model.carts) {
//            NSMutableArray *goodsList = [model.carts mutableCopy];
//            [goodsList removeObject:goodsModel1];
//            model.carts = goodsList;
//            return;
//        }
    }
}

- (void)deleteAllShopGoodsWithShopID:(NSString *)shopId {
    for (XOShoppingCartModel *model in self.list) {
        if ([model.shopId intValue] == [shopId intValue]) {
            model.carts = nil;
        }
    }
}

@end
